import 'package:flutter/material.dart';

class SimplePageView extends StatefulWidget {
  @override
  _SimplePageViewState createState() => _SimplePageViewState();
}

class _SimplePageViewState extends State<SimplePageView> {
  Axis _direction = Axis.horizontal;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8),
      height: 300,
      child: Column(
        children: [
          Expanded(
            flex: 1,
            child: PageView(
              controller: PageController(),
              scrollDirection: _direction,
              children: [
                Container(
                  color: Colors.red,
                  alignment: Alignment.center,
                  child: Text('page1', style: TextStyle(color: Colors.white)),
                ),
                Container(
                  color: Colors.green,
                  alignment: Alignment.center,
                  child: Text('page2', style: TextStyle(color: Colors.white)),
                ),
                Container(
                  color: Colors.blue,
                  alignment: Alignment.center,
                  child: Text('page3', style: TextStyle(color: Colors.white)),
                ),
              ],
            ),
          ),
          TextButton(
            child: Text('切换方向'),
            onPressed: () {
              setState(() {
                if (_direction == Axis.horizontal) {
                  _direction = Axis.vertical;
                } else {
                  _direction = Axis.horizontal;
                }
              });
            },
          ),
        ],
      ),
    );
  }
}
